package com.gsit.ocrbatch.services;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.gsit.ocrbatch.domain.Record;
import com.gsit.ocrbatch.domain.RecordState;

import static com.gsit.ocrbatch.utils.FileConstant.FILE_IN_PATH;
import static com.gsit.ocrbatch.utils.FileConstant.FILE_PROCESSED_PATH;

@Repository
public class OcrFileReader {
	
	

	public List<Record> findAllFile()throws IOException {
		List<Record> records = new ArrayList<>();
		File dir = new File(FILE_IN_PATH);
		if(dir.isDirectory()){
			for (File file : dir.listFiles()) {
				
				Record record = new Record();
				record.setName(file.getName());
				record.setPath(FILE_PROCESSED_PATH+"/"+file.getName());
				record.setCount(0);
				record.setRecordState(RecordState.WAITING);
				records.add(record);
			}
			
		}
		return records;
	}

}
